package com.huarui.quotation.action;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.ewaf.framework.action.BaseAction;

import com.huarui.params.Params;
import com.huarui.quotation.service.QuotationSearchService;
import com.huarui.util.FuncUtil;

public class QuotationSearchAction extends BaseAction{

	private static final long serialVersionUID = 1389475373041439907L;
	
	public final static String MESS = "mess";
	
	private String queryParam;
	
	private Map<String, Object> mesMap;
	
	private Integer start;
	
	private QuotationSearchService quotationSearchService;
	
	public void setQuotationSearchService(
			QuotationSearchService quotationSearchService) {
		this.quotationSearchService = quotationSearchService;
	}

	
	public String getQueryParam() {
		return queryParam;
	}

	public void setQueryParam(String queryParam) {
		this.queryParam = queryParam;
	}


	public Map<String, Object> getMesMap() {
		return mesMap;
	}

	public void setMesMap(Map<String, Object> mesMap) {
		this.mesMap = mesMap;
	}

	
	public Integer getStart() {
		return start;
	}

	public void setStart(Integer start) {
		this.start = start;
	}
	
	/**
	 * 搜索零件报价信息
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String searchQuotation() {
		Map<String, Object> paramsMap = null;
		if(queryParam == null) {
			paramsMap = new HashMap<String, Object>();
		} else {
			JSONObject jo = JSONObject.fromObject(queryParam);
			paramsMap = (Map<String, Object>) JSONObject.toBean(jo, HashMap.class);
		}
		paramsMap.put("start", start == null ? 0 : start);
		paramsMap.put("pageSize", Params.PAGE_SIZE);
		
		String ipAddress = super.httpServletRequest.getRemoteAddr();
		Long ip = FuncUtil.ip2Long(ipAddress);
		paramsMap.put("ip", ip);
		
		mesMap = this.quotationSearchService.searchQuotation(paramsMap);
		return MESS;
	}
	

}
